//
//  HomeInputView.m
//  HiCar
//
//  Created by huachun on 2019/4/11.
//  Copyright © 2019 丁一. All rights reserved.
//

#import "HomeInputView.h"

@interface HomeInputView ()<UITextFieldDelegate>

@end

@implementation HomeInputView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        CALayer *line = [CALayer new];
        line.frame=CGRectMake(0, 0, RECRWITCH, 0.8);
        line.backgroundColor = LineColor.CGColor;
        [self.layer addSublayer:line];
        
        self.backgroundColor = [UIColor whiteColor];
        
        _textField=[self textfield];
        [_textField setValue:[JonesClass stringTOColor:@"#666666"] forKeyPath:@"_placeholderLabel.textColor"];
        _textField.textColor=[UIColor blackColor];
        _textField.frame=CGRectMake(5, 2.5, RECRWITCH-10, frame.size.height-5);
        _textField.returnKeyType = UIReturnKeySend;
        [self addSubview:_textField];
        [_textField addTarget:self action:@selector(passConTextChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return self;
}



-(UITextField *)textfield{
    UITextField *textField=[[UITextField alloc] initWithFrame:CGRectMake(0, 0, RECR.size.width-30, 40)];
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 43)];
    textField.placeholder=@"请输入评论内容";
    textField.font=[UIFont systemFontOfSize:16];
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.returnKeyType=UIReturnKeyNext;
    textField.layer.borderWidth=0.0;
    textField.backgroundColor=[UIColor clearColor];
    textField.layer.borderColor=[UIColor clearColor].CGColor;
    [textField setValue:[JonesClass stringTOColor:@"#999999"] forKeyPath:@"_placeholderLabel.textColor"];
    textField.textColor=[JonesClass stringTOColor:@"#000000"];
    textField.delegate=self;
    
    CALayer *line=[CALayer new];
    line.frame=CGRectMake(0, 46, RECRWITCH, 0.7);
    line.backgroundColor=LineColor.CGColor;
    [textField.layer addSublayer:line];
    return textField;
}

-(void)passConTextChange:(id)sender{
    UITextField* target=(UITextField*)sender;
    if (target.text.length>100) {
        target.text = [target.text substringToIndex:100];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self PostPing_lun];
    return YES;
}

-(void)PostPing_lun{
    
    if (_textField.text==nil||[_textField.text isEqualToString:@""]) {
        return;
    }
    
    
    _selectblock(_textField.text);
    
}


@end
